package com.ordertracker.entity;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;

/**
 * Description of class.
 * Created 1/18/13 1:20 PM
 *
 * @author andrey.rodin@playtech.com
 */
@XmlRootElement
public abstract class VersionedEntity extends GeneralEntity implements Serializable {

    private Long version;

    @XmlElement
    public Long getVersion() {
        return version;
    }

    public void setVersion(Long version) {
        this.version = version;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof VersionedEntity)) return false;

        VersionedEntity that = (VersionedEntity) o;

        if (!version.equals(that.version) && !getId().equals(that.getId()))
            return false;

        return true;
    }

    @Override
    public int hashCode() {
        int i = getId().hashCode();
        i = 31 * i + version.hashCode();
        return i;
    }

    @Override
    public String toString() {
        return "id="+getId()+
                " version=" + version +
                '}';
    }
}
